﻿/*
 * Author: Branimir Topic (uxxx4663)
 * For: UC - ODD - Assignment 2B
 */

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;

namespace ARMS.Models
{
    #region Class InventoryItem
    public class InventoryItem
    {
        [Required]
        //[DataType(DataType.Custom)]
        [Display(Name = "Inventory ID")]
        public int id { get; set; }

        [Required]
        [Display(Name = "Shop ID")]
        public int shopID { get; set; }

        [Display(Name = "Description")]
        public string description { get; set; }

        [Display(Name = "Active")]
        public bool active { get; set; }
        public InventoryItem(int id, int shopid, string description, bool active)
        {
            this.id = id;
            this.shopID = shopid;
            this.description = description;
            this.active = active;
        }
    }
    #endregion

    #region Class Inventory Model
    public class InventoryModel : ARMS.BaseClasses.BaseModel
    {

        public InventoryModel() { }
        public DataTable getServices(int shopid)
        {
            string select = @"SELECT * FROM shopinventoryview";
            string where = @"";

            if (shopid > 0) where += String.Format(" shopid = {0}", shopid);

            string sql = (where.Length > 0) ? select + " WHERE " + where : select;
            sql += " ORDER BY shopid, description ASC";

            DataTable data = new DataTable();

            data = OpenTable(sql);

            return data;
        }
        public DataTable findItem(int id = 0, string name = null, bool isService = false)
        {

            string select = @"SELECT * FROM shopinventoryview";
            string where = @"";

            //validate id
            if (id > 0) where += String.Format(" id={0}", id);

            // validate name
            if (name.Length > 0) where += String.Format(" AND name={0}", name);

            string sql = (where.Length > 0) ? select + " WHERE " + where : select;

            DataTable data = OpenTable(sql);

            return data;
        }
    }
    #endregion Class Inventory Model
}